<?php
include './src/CRedis.php';

class MetalApi{

	/**
	 * 获取今天的数据
	 */
	public static function getHistoryData($day) {
		
		$file = __DIR__.'/test/data/'.date('Y-m-d').'.txt';
		
		if(is_file($file)) readfile($file);
		
	}
	
	/**
	 * 获取实时数据
	 */
	public static function getLastRecord() {
		
		$time = time()-10;
		$time -= $time%10;
		
		$redis = new CRedis;
		
		$data = '';
		for($i = 0; $i < 3; $i++) {
			$time -= $i * 10;
			
			$t = date('H:i:s', $time);
			
			$data = $redis->get('fx_metal_'.$t);
			
			if($data) break;
		}
		
		echo $data;
	}

}

if(isset($_GET['day'])) {
	MetalApi::getHistoryData($_GET['day']);
} else {
	MetalApi::getLastRecord();
}